package org.csu.gp_store.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.csu.gp_store.entity.OrderItem;
import org.csu.gp_store.mapper.OrderItemMapper;
import org.csu.gp_store.service.OrderItemService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderItemServiceImpl implements OrderItemService {

    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public List<OrderItem> getOrderItemsByCompanyID(@NotNull Long companyID) {
        QueryWrapper<OrderItem> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("companyID",companyID);
        return orderItemMapper.selectList(queryWrapper);
    }

    @Override
    public int manageOrder(OrderItem orderItem) {
        return orderItemMapper.update(orderItem,null);
    }

    @Override
    public List<OrderItem> getOrderItemsByOrderID(@NotNull Long orderID) {
        QueryWrapper<OrderItem>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("orderID",orderID);
        return orderItemMapper.selectList(queryWrapper);
    }

    @Override
    public OrderItem getOrderItemByIndexID(@NotNull Long indexID) {
        return orderItemMapper.selectById(indexID);
    }

    @Override
    public List<OrderItem> getOrderItemListLikeProductName(@NotNull String productName) {
        QueryWrapper<OrderItem> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("product_name",productName);
        return orderItemMapper.selectList(queryWrapper);
    }

    @Override
    public int updateOrderItemStatus(@NotNull Long indexID, int status) {
        UpdateWrapper<OrderItem> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("indexID",indexID).set("status",status);
        return orderItemMapper.update(null,updateWrapper);
    }

    @Override
    public int insertOrderItem(OrderItem orderItem) {
        return  orderItemMapper.insert(orderItem);
    }

    @Override
    public int deleteOrderItem(@NotNull Long orderID) {
        QueryWrapper<OrderItem> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("orderID",orderID);
        return orderItemMapper.delete(queryWrapper);
    }
}
